﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "入厂采样信息";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div id="uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
</div>
<div id="modalwindow" class="easyui-window" style="width:900px; height:450px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<table style="width:100%">
    <tbody>
        <tr>
            <td style="width:100%;vertical-align: top" colspan="2">
                <div class="mvctool">
                    <input id="LPR" type="text" class="searchText" style="width:100px" placeholder="车牌号" />
                    <input id="RFID" type="text" class="searchText" style="width:100px" placeholder="样桶卡号" />
                    <input id="PAIL" type="text" class="searchText" style="width:100px" placeholder="样桶序号" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
                    <input id="BATCH_CODE" type="text" class="searchText" style="width:100px" placeholder="批次编码" />
                    <select class="easyui-combobox" name="MATERIEL_ID" id="MATERIEL_ID" style="width:100px;"></select>
                    <select name="SAMPLING_NODE" id="SAMPLING_NODE">
                        <option value="0">===采样机===</option>
                        <option value="南侧采样机">南侧采样机</option>
                        <option value="北侧采样机">北侧采样机</option>
                    </select>
                    @Html.DropDownList("SAMPLING_STATUS", EnumMvcHelper.GetMVCSelectList<Wantn.FIS.Enum.SamplingState>("===采样状态==="), new { @style = "width:130px" })
                    <select class="easyui-combobox" name="SUPPLIER_ID" id="SUPPLIER_ID" style="width:250px;"></select>
                    @*<input id="SAMPLING_USER_NAME" type="text" class="searchText" style="width:100px" placeholder="采样员" />*@
                    <input id="SAMPLING_BEGIN_TIME" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', maxDate: '#F{$dp.$D(\'SAMPLING_END_TIME\')}' })" type="text" class="searchText" style="width:100px" placeholder="采样开始时间" />
                    <input id="SAMPLING_END_TIME" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'SAMPLING_BEGIN_TIME\')}' })" type="text" class="searchText" style="width:100px" placeholder="采样结束时间" />
                    @Html.ToolButton("btnQuery", "fa fa-search", Resource.Query, ref perm, "Query", true)
                    @Html.ToolButton("btnBuChong", "fa fa-list", "补充采样信息", ref perm, "BuChong", true)
                    @Html.ToolButton("btnBjError", "fa fa-list", "标记无效", ref perm, "BjError", true)
                    
                    @Html.ToolButton("btnExport", "fa fa-level-up", Resource.Export, ref perm, "Export", true)
                </div>
                <div>
                    <table id="ListParent"></table>
                </div>
            </td>
        </tr>
        <tr>
            <td style="vertical-align:top">
                <table id="List"></table>
            </td>
            <td style="vertical-align:top">
                <table style="width:710px;vertical-align:top;">
                    <tr>
                        <td style="width:350px;height:25px">采样前图片</td>
                        <td style="width:350px;height:25px"></td>
                        <td>采样后图片</td>
                    </tr>
                    <tr>
                        <td style="width:350px"><img id="Before_Img" style="width:350px;" onclick="ShowBigImg(1)" /></td>
                        <td style="width:10px"></td>
                        <td style="width:350px"><img id="After_Img" style="width:350px;" onclick="ShowBigImg(2)" /></td>
                    </tr>
                </table>
            </td>
        </tr>
    </tbody>
</table>

<script src="~/Scripts/common.js"></script>
<script type="text/javascript">
    $(function () {

        GetTranSuppList(2, "@ViewBag.MATERIEL_ID");

        $('#ListParent').datagrid({
            url: '@Url.Action("GetListParent")',
            width: SetGridWidthSub(20),
            methord: 'post',
            height: SetGridHeightSub(250),
            fitColumns: false,
            sortName: 'SAMPLING_BEGIN_TIME',
            sortOrder: 'desc',
            idField: 'SAMPLING_ID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onLoadSuccess: function(data) {
                setTimeout(function () {
                    $('#ListParent').datagrid("selectRow", 0);
                    var row = $('#ListParent').datagrid('getSelected');
                    if (row != null) {
                        $('#List').datagrid("load", { parentId: row.SAMPLING_ID });
                        $("#Before_Img").attr("src", "@Url.Action("SamplingImg")?SAMPLING_ID="+row.SAMPLING_ID+"&ImgType=1");
                        $("#After_Img").attr("src","@Url.Action("SamplingImg")?SAMPLING_ID="+row.SAMPLING_ID+"&ImgType=2");
                    }
                }, 1000);
            },
            columns: [[
                { field: 'SAMPLING_ID', title: 'SAMPLING_ID', width: 80, hidden: true },
                { field: 'ISERROR', title: '采样状态', width: 80, sortable: true, formatter: function (value) { return EnableFormatterError(value) } },
                { field: 'BATCH_CODE', title: '批次编码', width: 80,sortable:true },
                { field: 'RFID', title: '桶卡号', width: 140,sortable:true },
                { field: 'MATERIEL_NAME', title: '物料', width: 80, sortable: true },
                { field: 'SUPPLIER_NAME', title: '供应商', width: 180,sortable:true },
                { field: 'TRANSPORT_NAME', title: '运输商', width:180,sortable:true },
                { field: 'LPR', title: '车牌号', width: 80,sortable:true },
                { field: 'SAMPLING_NODE_NAME', title: '采样机', width: 80,sortable:true },
                { field: 'SAMPLE_PAIL', title: '采样桶号', width: 80,sortable:true },
                { field: 'SAMPLING_TYPE', title: '采样方式', width: 80,sortable:true,formatter:@Html.Raw(EnumMvcHelper.GridFormatterFunc<Wantn.FIS.Enum.SamplingType>()) },
                { field: 'LAYOUT_TYPE', title: '布点方式', width: 90,sortable:true,formatter:@Html.Raw(EnumMvcHelper.GridFormatterFunc<Wantn.FIS.Enum.LayoutType>()) },
                { field: 'SAMPLING_POINTS', title: '采样点数', width: 80,sortable:true },
                { field: 'SAMPLE_WEIGHT', title: '样品重量（kg）', width: 80,sortable:true },
                { field: 'SAMPLING_BEGIN_TIME', title: '采样开始时间', width: 160,sortable:true },
                { field: 'SAMPLING_END_TIME', title: '采样结束时间', width: 160,sortable:true },
                { field: 'SAMPLING_STATUS', title: '采样状态', width: 80,sortable:true,formatter:@Html.Raw(EnumMvcHelper.GridFormatterFunc<Wantn.FIS.Enum.SamplingState>()),hidden:true },
                { field: 'SAMPLING_USER_NAME', title: '采样员', width: 80, sortable: true },
                { field: 'REVICED', title: '已交接', width: 80, sortable: true, formatter: function (value) { return EnableFormatterNember(value) } },
                { field: 'BLENDED', title: '已合样', width: 80, sortable: true, formatter: function (value) { return EnableFormatterNember(value) } },
                { field: 'MADE', title: '已制样', width: 80, sortable: true, formatter: function (value) { return EnableFormatterNember(value) } },

            ]]
         ,onClickRow: function(index, row) {
             $('#List').datagrid("load", { parentId: row.SAMPLING_ID });
             $("#Before_Img").attr("src", "@Url.Action("SamplingImg")?SAMPLING_ID="+row.SAMPLING_ID+"&ImgType=1");
             $("#After_Img").attr("src","@Url.Action("SamplingImg")?SAMPLING_ID="+row.SAMPLING_ID+"&ImgType=2");

         }
        });

        if (@Html.FieldShow(ref perm,"IsShow")== 0) {
            $('#ListParent').datagrid('hideColumn', 'MATERIEL_NAME');
            $('#ListParent').datagrid('hideColumn', 'SUPPLIER_NAME');
            $('#ListParent').datagrid('hideColumn', 'TRANSPORT_NAME');
        }

        $("#Before_Img").height(SetGridHeightSub(40)-SetGridHeightSub(220));
        $("#After_Img").height(SetGridHeightSub(40)-SetGridHeightSub(220));

         $(window).resize(function() {
             resizeLayout();
        });

        $('#List').datagrid({
            url: '@Url.Action("GetList")?parentId=0',//+$('#ListParent').datagrid('getSelected').SAMPLING_ID,
            width:SetGridWidthSub(730),
            methord: 'post',
            height: SetGridHeightSub(40)-SetGridHeightSub(250),
            fitColumns: true,
            sortName: 'POINT_NO',
            sortOrder: 'desc',
            idField: 'POINT_NO',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: false,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onLoadSuccess: function (data) {
                @foreach(var r in perm){ if (r.Category == 2) { @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); "); } }
            },
            columns: [[
                { field: 'SAMPLING_ID', title: '采样编号', width: 80,hidden:true },
                { field: 'X', title: 'X坐标', width: 20,sortable:true },
                { field: 'Y', title: 'Y坐标', width: 20,sortable:true },
                { field: 'Z', title: 'Z坐标', width: 20,sortable:true },
                { field: 'BLOCK_NO', title: '块号', width: 20,sortable:true },
                { field: 'POINT_NO', title: '点号', width: 20,sortable:true }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
        {
            $("#List,#ListParent").datagrid('load');
        }
        else
        {
            $("#List,#ListParent").datagrid('reload');
        }
    }

    function ShowBigImg(type)
    {
        var row = $('#ListParent').datagrid('getSelected');
        if (row != null) {
            $("#modalwindow").html("<img style='width:100%;height:100%' src='@Url.Action("SamplingImg")?SAMPLING_ID="+row.SAMPLING_ID+"&ImgType="+type+"&Ieguid=" + GetGuid() + "' />");
            $("#modalwindow").window({ title: '查看图片', width: 800, height: 450, iconCls: 'fa fa-pencil' }).window('open');
        }
        else
        {
            $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords');
        }
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }

    $("#btnBjError").click(function () {
             var row = $('#ListParent').datagrid('getSelected');
             if (row != null) {
                 $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("BjError")?samplingId=" + row.SAMPLING_ID + "&Ieguid=" + GetGuid() + "'></iframe>");
             $("#modalwindow").window({ title: '标记为无效采样信息', width:400, height: 600, iconCls: 'fa fa-pencil' }).window('open');
             } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
    });

    $("#btnBuChong").click(function () {
         var row = $('#ListParent').datagrid('getSelected');
         if (row != null) {
             $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("BuChong")?samplingId=" + row.SAMPLING_ID + "&Ieguid=" + GetGuid() + "'></iframe>");
         $("#modalwindow").window({ title: '补充采样信息', width:400, height: 600, iconCls: 'fa fa-pencil' }).window('open');
         } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
    });

    $(function () {
        $("#btnQuery").click(function () {
            var LPR = $("#LPR").val();
            //var RFID = $("#RFID").val();
            var BATCH_CODE = $("#BATCH_CODE").val();
            var SAMPLING_STATUS = $("#SAMPLING_STATUS").val();
            var SUPPLIER_ID = $('#SUPPLIER_ID').combobox('getValues').toString(); //$("#SUPPLIER_ID").val();

            var SAMPLING_USER_NAME = $("#SAMPLING_USER_NAME").val();
            var SAMPLING_BEGIN_TIME = $("#SAMPLING_BEGIN_TIME").val();
            var SAMPLING_END_TIME = $("#SAMPLING_END_TIME").val();
            var PAIL = $("#PAIL").val();
            var RFID = $("#RFID").val();

            var MATERIEL_ID = $("#MATERIEL_ID").combobox('getValues').toString();
            var SAMPLING_NODE = $("#SAMPLING_NODE").val();
            $("#ListParent").datagrid("load", { LPR: LPR, BATCH_CODE: BATCH_CODE, SAMPLING_STATUS: SAMPLING_STATUS, SUPPLIER_ID: SUPPLIER_ID, SAMPLING_USER_NAME: SAMPLING_USER_NAME, SAMPLING_BEGIN_TIME: SAMPLING_BEGIN_TIME, SAMPLING_END_TIME: SAMPLING_END_TIME, PAIL: PAIL, MATERIEL_ID: MATERIEL_ID, SAMPLING_NODE: SAMPLING_NODE, RFID: RFID });

        });

        $("#btnExport").click(function() {

            var LPR = $("#LPR").val();
            var BATCH_CODE = $("#BATCH_CODE").val();
            var SAMPLING_STATUS = $("#SAMPLING_STATUS").val();
            var SUPPLIER_ID = $("#SUPPLIER_ID").val();
            var SAMPLING_USER_NAME = $("#SAMPLING_USER_NAME").val();
            var SAMPLING_BEGIN_TIME = $("#SAMPLING_BEGIN_TIME").val();
            var SAMPLING_END_TIME = $("#SAMPLING_END_TIME").val();

            $.post("@Url.Action("CheckExportData")?LPR="+LPR+"&BATCH_CODE="+BATCH_CODE+"&SAMPLING_STATUS="+ SAMPLING_STATUS+"&SUPPLIER_ID="+SUPPLIER_ID+"&SAMPLING_USER_NAME="+SAMPLING_USER_NAME+"&SAMPLING_BEGIN_TIME="+SAMPLING_BEGIN_TIME+"&SAMPLING_END_TIME="+SAMPLING_END_TIME, function(data) {
                if (data.type == 1)
                {
                    window.location = "@Url.Action("Export")?LPR="+LPR+"&BATCH_CODE="+BATCH_CODE+"&SAMPLING_STATUS="+ SAMPLING_STATUS+"&SUPPLIER_ID="+SUPPLIER_ID+"&SAMPLING_USER_NAME="+SAMPLING_USER_NAME+"&SAMPLING_BEGIN_TIME="+SAMPLING_BEGIN_TIME+"&SAMPLING_END_TIME="+SAMPLING_END_TIME;
                }
                else
                {
                $.messageBox5s(Lang.Tip, data.message);
                }
            }, "json");
        });


        $.ajax({
            url: '@Url.Action("GetTranSuppList")?type=0',
            type:'post',
            dataType: 'json',
            success: function (result) {
                $('#SUPPLIER_ID').combobox({
                    data: result,
                    valueField: 'Value',
                    textField:'Text',
                    onLoadSuccess : function() {
                        $("#SUPPLIER_ID").combobox("setValue", "-1");
                    }

                });

            },
        });
    });

    function resizeLayout()
     {
         setTimeout(function () {
             $('#ListParent').datagrid('resize', {
             }).datagrid('resize', {
                 width: SetGridWidthSub(10),
             });
             $('#List').datagrid('resize', {
             }).datagrid('resize', {
                 width: $(window).width() - 420,
             });
             $("#Before_Img").height(SetGridHeightSub(40)-SetGridHeightSub(200));
             $("#After_Img").height(SetGridHeightSub(40)-SetGridHeightSub(200));
         },100);
	    }
</script>

